﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NewLife.Web;
using NewsPub;
using XCode;
using NewLife;

public partial class List : MyPageBase<Classis>
{
    /// <summary>编号</summary>
    public Int32 EntityID { get { if (WebHelper.RequestInt("id") == 0)Response.Redirect("Default.aspx"); return WebHelper.RequestInt("id"); } }

    private Classis __Entity;
    /// <summary>客户</summary>
    public Classis Entity
    {
        get { return __Entity ?? (__Entity = Classis.FindByID(EntityID));  }
        set { __Entity = value; }
    }
    int pageSize = 2;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Entity.ID == 0) Response.Redirect("Default.aspx");
            if (Entity.IsShow == false) Response.Redirect("Default.aspx");
            //HtmlGenericControl Title = new HtmlGenericControl();
            this.Master.Page.Title = Entity.Name + "-尤溪县环境保护局";
            //txtKey.Text = EntityID.ToString();
            //DataBind(); 
            Label7.Text = Entity.AllChilds.Count == 0 ? Entity.ParentClassisName : Entity.Name;
            Label8.Text = Entity.ParentID == 0 ? "<a href='" + Entity.ListUrl + "?id=" + Entity.ID + "'>" + Entity.Name + "</a>" : "<a href='" + Entity.ListUrl + "?id=" + Entity.ParentID + "'>" + Entity.ParentClassisName + "</a>" + "&nbsp;&gt;&nbsp; <a href='" + Entity.ListUrl + "?id=" + Entity.ID + "'>" + Entity.Name + "</a>";
            //rptleftmenusub.DataSource = Classis.FindByID(Entity.Childs.Count==0?Entity.ParentID: Entity.ID).AllChilds;
            //rptleftmenusub.DataBind();
            //int sid = WebHelper.RequestInt("sid"); int id = WebHelper.RequestInt("id");
            //EntityList<Details> delist = null;
            //delist = Details.FindALLByClassisID(Entity.ID);
            //delist = Details.  (.FindCount(Classis.FindAllByParent(1).ToArray()[1],Entity.ID,"",0,0);//   .FindAllByClassisID(.FindAll("ClassisId", Entity.ID, 0, 5);
            //delist = Details.FindAll("select * from details where classisid in (select id from classis where parentid=" + EntityID + " or id=" + EntityID + ") limit 0,5");
            //delist = Details.SearchList(EntityID.ToString(), "CreateTime desc", 0, pageSize);
            ////按创建时间反排序
            ////delist.Sort("CreateTime", true);
            
            //rptlist.DataSource = delist;
            //rptlist.DataBind();
            //pager.PageSize = pageSize;
            //pager.TotalRowCount = Details.SearchListCount(EntityID.ToString(), "CreateTime DESC", 0, 0);
            //if (pager.TotalRowCount <= pageSize) pager.Visible = false;
            //else { delist = Details.FindAll("select * from details where classisid=" + id); delist.Sort("CreateTime", true); rptlist.DataSource = delist; rptlist.DataBind(); }
            //rptcategorylist.DataSource
            //Classis.FindAllByParent
        }
    }
    protected void rptleftmenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        //Repeater dlproduct = (Repeater)e.Item.FindControl("rptleftmenusub");
        ////DataRowView rowv = (DataRowView)e.Item.DataItem;
        //Classis rowv = (Classis)e.Item.DataItem;
        //int CategoryId = Convert.ToInt32(rowv["ID"]);
        //Classis classis = new Classis();
        //dlproduct.DataSource = Classis.FindAllByParentID(CategoryId).ToDataTable(false);
        //dlproduct.DataBind();
    }
    protected void DataPager2_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        //Search(e.NewPageIndex);
    }
    void Search(Int32 index)
    {


        // 总行数

        //pager.TotalRowCount = Details.SearchListCount(EntityID.ToString(), "CreateTime DESC", 0, 0);
        //pager.PageSize = pageSize;

        ////String tableName = ddlTable.SelectedValue;
        ////String fsql = String.Format("Select * From {0}", dal.Db.FormatKeyWord(tableName));
        ////if (sql.ToLower().StartsWith(fsql.ToLower()))
        ////{
        ////    IEntityOperate factory = dal.CreateOperate(tableName);
        ////    if (factory != null)
        ////    {
        ////        gvResult.DataSource = factory.FindAll(sql.Substring(fsql.Length), null, null, index * gvResult.PageSize, gvResult.PageSize);
        ////        gvResult.DataBind();
        ////        return;
        ////    }
        ////}

        ////String key = txtKey.Text;
        ////if (String.IsNullOrEmpty(key)) key = "ID";

        ////sql = dal.PageSplit(sql, index * gvResult.PageSize, gvResult.PageSize, key);

        ////DataSet ds = dal.Select(sql, "");
        ////gvResult.DataSource = ds;
        ////gvResult.DataBind();
        //EntityList<Details> delist = null;
        //delist = Details.SearchList(EntityID.ToString(), "CreateTime desc", index * pageSize, pageSize);
        //    //按创建时间反排序
        //    //delist.Sort("CreateTime", true);
        //    rptlist.DataSource = delist;
        //rptlist.DataBind();
    }
    //protected void pager_PageCommand(object sender, CommandEventArgs e)
    //{
    //    odssubmenu.DataBind();
    //}
    protected void pager_PageIndexChanged(object sender, EventArgs e)
    {
        rptleftmenusub.DataSourceID = "odssubmenu";
        rptleftmenusub.DataBind();
    }
}